import java.util.Scanner;


public class QuickSort
{

	public static void main(String[] args)
	{		
		Scanner input = new Scanner(System.in);
		
		System.out.print("n degeri girin: ");
		int a[] = new int[Integer.parseInt(input.nextLine().trim())];
		
		System.out.println("a degerleri rastgele atandi");
		for(int i = 0; i < a.length; i++)
			a[i] = (int) (Math.random() * 100);
		
		hizliSirala(a, 0, a.length -1);
		
		System.out.println("Sirali dizi:");
		for(int i : a)
			System.out.print(i + " ");
		
		input.close();
	}

	public static void hizliSirala(int a[], int sol, int sag)
	{
		int i = sol, j = sag, h;
		int x = a[(sol + sag) / 2];
		
		do
		{
			while(a[i] < x)
				i++;
		
			while(a[j] > x) 
				j--;
			
			if(i <= j)
			{
				h = a[i]; a[i] = a[j]; a[j] = h;
				i++; j--;
			}
		}while(i <= j);
		
		if(sol < j) hizliSirala(a, sol, j);
		if(sag > i) hizliSirala(a, i, sag);
	}
}
